package com.gxt.riaapp.client.mvc;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.TreeModel;
import com.gxt.riaapp.client.mvc.model.Category;
import com.gxt.riaapp.client.mvc.model.Entry;

public class RiaAppModel  extends BaseTreeModel {
	protected List<Entry> entries = new ArrayList<Entry>();
	public RiaAppModel()   {
		Category pgm = new Category("시스템관리","SYS00002");
		pgm.add("시스템사용자관리1", "0001", new SmplProgram("시스템사용자관리1"));
		pgm.add("시스템사용자관리2", "0002", new SmplProgram("시스템사용자관리2"));
		pgm.add("시스템사용자관리3", "0003", new SmplProgram("시스템사용자관리3"));
		pgm.add("시스템사용자관리4", "0004", new SmplProgram("시스템사용자관리4"));
		
		addCategory(pgm);
		loadEntries(this);
	}
	public void addCategory(ModelData child) {
//		try{
//			 Class t = Class.forName("com.gxt.riaapp.client.mvc.SmplProgram");
//			}catch(java.lang.ClassNotFoundException e){
//				System.out.println(e.toString());
//			}
		if(child != null)
			add(child);
	  }
	public List<Entry> getEntries() {
		return entries;
	}
	
	private void loadEntries(TreeModel model) {
		for (ModelData child : model.getChildren()) {
			if (child instanceof Entry) {
				entries.add((Entry) child);
			} else if (child instanceof Category) {
				loadEntries((Category) child);
			}
		}
	}
}
